int LED1 = 9;   //Set the door lock mechanism status
int LED2 = 10;  //Set the lamp (lock and unlock) notification
int Car = 11;   //Set Car door open or close
char A;         //Receive command 'L' or 'U'

void setup() {
   Serial.begin(9600);
   pinMode(LED1,OUTPUT); // Assign LED1 as output
   pinMode(LED2,OUTPUT); // Assign LED2 as output
   pinMode(Car, INPUT);  // Assign Car as input
}

void loop() {
    
    A = Serial.read();   // Read the command 
    
    
    switch(A) { 
      // Set the car to be lock 
      case 'L':
        if(digitalRead(Car)== HIGH && digitalRead(LED1) == LOW) {
         digitalWrite(LED1, HIGH);
         digitalWrite(LED2, HIGH);   // turn the LED on 
         delay(1000);                // wait for a second
         digitalWrite(LED2, LOW);    // turn the LED off by making the voltage LOW
         break;
        }
        else if(digitalRead(LED1)== LOW) {
         break;
        }
      // Set the car to unlock 
      case 'U':
        if(digitalRead(LED1) == HIGH) {
         digitalWrite(LED1, LOW);
         digitalWrite(LED2, HIGH);   // turn the LED on 
         delay(1000);                // wait for a second
         digitalWrite(LED2, LOW);    // turn the LED off
         delay(1000);                // wait for a second
         digitalWrite(LED2, HIGH);   // turn the LED on 
         delay(1000);                // wait for a second
         digitalWrite(LED2, LOW);    // turn the LED off
         break;  
        }
    }
 }
 
